<?php
/**
 * 配置类
 *
 * @author keluo<pycorvn@yeah.net>
 * @since 2015-01-24
 * @example
 * 读取配置信息项目：
 * echo SCS::config()->connect;
 * echo SCS::config()->db['default'];
 */
class SCConfig {
    
    private static $_instance;
    private $_configs = null;
    
    private function __construct() {
        $configFile = SC_CONFIG_PATH.'/config.php';
        if(file_exists($configFile) && is_file($configFile)) {
            $this->_configs = require SC_CONFIG_PATH.'/config.php';
            is_array($this->_configs) || $this->_configs = array();
        } else {
            throw new Exception('没有找到配置文件：'.$configFile.'，如果是第一次运行此项目，
                请尝试在index.php中添加代码“SCScabish::init();”进行初始化', E_USER_ERROR);
        }
    }
    
    public function __clone() {}
    
    public static function instance() {
        if(!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
    
    public function __get($item) {
        return isset($this->_configs[$item]) ? $this->_configs[$item] : null;
    }
    
}